package pers.cz.flowcell;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.xml.sax.SAXException;
import pers.cz.mxgraph.MxGraphModel;

import javax.xml.parsers.ParserConfigurationException;
import java.io.ByteArrayInputStream;
import java.io.IOException;

/**
 * @program: jef-flow-spring-boot-starter
 * @description: xml解析器
 * @author: Cheng Zhi
 * @create: 2023-02-12 15:58
 **/
public class JefFlowXmlParser implements JefFlowParser {

    /**
     * XML 文件
     */
    private final String xml;

    /**
     * 图形信息
     * @param xml
     */
    public JefFlowXmlParser(String xml) {
        this.xml = xml;
    }

    /**
     * 解析MxGrapth
     * @return 解析
     * @throws ParserConfigurationException 解析配置异常
     * @throws SAXException SAX 异常
     * @throws IOException Io Exception
     */
    public Document parse() throws DocumentException {
        //1.创建Reader对象
        SAXReader reader = new SAXReader();
        reader.setEncoding("utf-8");
        //2.加载xml
        Document document = reader.read(new ByteArrayInputStream(xml.getBytes()));
        return document;
    }

}
